import collections
class Solution(object):
    def relativeSortArray(self, arr1, arr2):
        """
        :type arr1: List[int]
        :type arr2: List[int]
        :rtype: List[int]
        """
        out = []
        c = collections.Counter(arr1)
        d = set(arr2)
        t = []
        for num in arr2:
            out.extend([num] * c[num])
        for key in c:
            if key not in d:
                t.append(key)
        t.sort()
        for num in t:
            out.extend([num] * c[num])
        return out
